<template>
    <div class="comment-item">
        <div class="comment-header">
            <el-avatar :src="comment.userAvatar" />
            <span class="author">{{ comment.userNickname }}</span>
            <span class="time">{{ formatTime(comment.createTime) }}</span>
        </div>
        <div class="comment-content">{{ comment.content }}</div>

        <!-- 回复按钮和子评论 -->
        <div class="comment-actions">
            <!-- <el-button size="small" @click="$emit('reply', comment)">回复</el-button> -->
            <el-button size="small" @click=" emit('view-floor', comment);">共{{ comment.floorAmount }}条回复</el-button>
        </div>
    </div>
</template>

<script setup>

defineProps({
    avatar: {
        type: String,
  },
  comment: {
    type: Object,
    required: true
    },
    name: {
      type: String
  }
});

const formatTime = (time) => {
  return new Date(time).toLocaleString();
};

const emit = defineEmits(['reply', 'view-floor']);

const viewfloorComment = () => {
   // 触发查看楼层事件
};
</script>

<style scoped>
.comment-item {
  padding: 10px;
  margin: 10px 0;
  border-radius: 4px;
  background: #f8f9fa;
}

.comment-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #666;
  margin-bottom: 5px;
}

.author {
  font-weight: 500;
}

.time {
  font-size: 0.9em;
  color: #999;
}

.comment-content {
  margin-left: 28px;
}

.replies {
  margin-left: 30px;
  border-left: 2px solid #eee;
  padding-left: 15px;
}

.comment-actions {
  margin-top: 8px;
  margin-left: 28px;
}
</style>
